﻿// Decompiled with JetBrains decompiler
// Type: XamlEditor.LineArrowAdorner
// Assembly: XamlEditor, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
// MVID: 2AF0471B-7BFE-4738-893B-A4F91E243353
// Assembly location: C:\Users\KasimGulcan\Desktop\Kosgeb\DynaCAD\Project\lib\XamlEditor.dll

using LineWithArrows;
using System.Windows;
using System.Windows.Controls.Primitives;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;

namespace XamlEditor
{
  public class LineArrowAdorner : Adorner
  {
    private Thumb Start;
    private Thumb End;
    private VisualCollection VisualChildren;

    protected override int VisualChildrenCount
    {
      get
      {
        return this.VisualChildren.Count;
      }
    }

    public LineArrowAdorner(LineArrow AdornedElement)
      : base((UIElement) AdornedElement)
    {
      this.VisualChildren = new VisualCollection((Visual) this);
      this.Start = new Thumb();
      this.End = new Thumb();
      this.BuildAdorners();
      this.ThumbHandler();
    }

    private void BuildAdorners()
    {
      this.Start.Height = this.Start.Width = 10.0;
      this.Start.Opacity = 0.8;
      this.Start.Background = (Brush) new SolidColorBrush(Colors.Black);
      this.Start.Style = (Style) this.FindResource((object) "Arrow");
      this.VisualChildren.Add((Visual) this.Start);
      this.End.Height = this.End.Width = 10.0;
      this.End.Opacity = 0.8;
      this.End.Background = (Brush) new SolidColorBrush(Colors.Black);
      this.End.Style = (Style) this.FindResource((object) "Arrow");
      this.VisualChildren.Add((Visual) this.End);
    }

    private void ThumbHandler()
    {
      this.Start.DragDelta += new DragDeltaEventHandler(this.StartDragDelta);
      this.End.DragDelta += new DragDeltaEventHandler(this.EndDragDelta);
    }

    private void StartDragDelta(object sender, DragDeltaEventArgs e)
    {
      LineArrow lineArrow = this.AdornedElement as LineArrow;
      Point position = Mouse.GetPosition((IInputElement) lineArrow.Parent);
      lineArrow.StartPoint = position;
    }

    private void EndDragDelta(object sender, DragDeltaEventArgs e)
    {
      LineArrow lineArrow = this.AdornedElement as LineArrow;
      Point position = Mouse.GetPosition((IInputElement) lineArrow.Parent);
      lineArrow.EndPoint = position;
    }

    protected override void OnRender(DrawingContext drawingContext)
    {
      Rect rect = new Rect(this.AdornedElement.DesiredSize);
      LineArrow lineArrow = this.AdornedElement as LineArrow;
      SolidColorBrush solidColorBrush = new SolidColorBrush(Colors.Green);
      solidColorBrush.Opacity = 0.3;
      Pen pen = new Pen((Brush) solidColorBrush, 1.5);
      drawingContext.DrawRectangle((Brush) null, pen, new Rect(new Point(0.0, 0.0), new Point(lineArrow.Width, lineArrow.Height)));
    }

    protected override Size ArrangeOverride(Size finalSize)
    {
      LineArrow lineArrow = this.AdornedElement as LineArrow;
      this.Start.Arrange(new Rect(new Point(-20.0, -20.0), new Point(lineArrow.StartPoint.X * 2.0 + 20.0, lineArrow.StartPoint.Y * 2.0 + 20.0)));
      this.End.Arrange(new Rect(new Point(-20.0, -20.0), new Point(lineArrow.EndPoint.X * 2.0 + 20.0, lineArrow.EndPoint.Y * 2.0 + 20.0)));
      return finalSize;
    }

    protected override Visual GetVisualChild(int index)
    {
      return this.VisualChildren[index];
    }
  }
}
